<!---->
<script>
import { labelAdd, labelDel, labelModify, labelview, userListview } from '@/api/system/api'

export default {
  data() {
    return {
      flag:'',
      labelId: {
        ids: ''
      },

      labelName: {
        label: ''
      },
      labelData: {},
      dialogVisible: false,
      tableData: []
    }

  },
  created() {
    this.labelAll()
    // labelview({
    //   pageSize: 15,
    //   pageNum: 1
    // }).then(res => {

    //   this.tableData = res.rows
    // })
    // userListview().then(res => {

    //
    // })
    this.allList()
  },
  methods: {
    allList(){
      userListview().then(res => {

      })
    },
labelAll(){
  labelview({
    pageSize: 15,
    pageNum: 1
  }).then(res => {

    this.tableData = res.rows
  })
},
    del(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除个案咨询档案编号为"' + ids + '"的数据项？').then(function() {

        return labelDel({
          ids:ids}
        ).then(res => {


        })
      }).then(() => {
        this.$modal.msgSuccess('删除成功')
        labelview({
          pageSize: 15,
          pageNum: 1
        }).then(res => {

          this.tableData = res.rows
        })
      }).catch(() => {
      })

    },

    storage() {
      this.flag=true
      this.$message({
        message: '操作成功',
        type: 'success'

      });
     this.allList()
      this.dialogVisible = false
      labelModify({ ...this.labelName }).then(res => {


      })
    },
    save(row) {
      this.flag=false

      this.dialogVisible = true
      this.$modal.msgSuccess('操作成功')
      this.labelName = JSON.parse(JSON.stringify(row))
    },
    determine() {
      this.flag=false
      this.$message({
        message: '操作成功',
        type: 'success'
      });
      this.dialogVisible = false
      labelAdd(this.labelName).then(res => {
        labelview({
          pageSize: 15,
          pageNum: 1
        }).then(res => {

          this.tableData = res.rows
        })
      })
      labelview({
        pageSize: 15,
        pageNum: 1
      }).then(res => {

        this.tableData = res.rows
      })
    },
    addData() {
      this.flag=true
      this.dialogVisible = true
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
          labelview({
            pageSize: 15,
            pageNum: 1
          }).then(res => {

            this.tableData = res.rows
          })
        })
        .catch(_ => {

        })
    }
  }
}


</script>

<template>
  <div>
    <div class="content">
      <el-button type="primary" @click="addData">添加</el-button>
    </div>
    <div class="content">
      <template>
        <el-table
          :data="tableData"
          style="width: 100%"
        >
          <el-table-column
            prop="label"
            label="名称"

            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="updateTime"
            label="更新时间"

            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="address"
            label="操作"
            align="center"
          >
            <template slot-scope="scope">
              <a class="characters" @click="save(scope.row)">编辑</a>
              <a class="characters" @click="del(scope.row)">删除</a>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <div> 标签名称:
        <el-input v-model="labelName.label" placeholder="请输入内容" style="width: 70%"></el-input>
      </div>
      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="determine" v-show="flag">确 定</el-button>
       <el-button type="primary" @click="storage" v-show="!flag">保存</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<style scoped lang="scss">

.content {
  margin-top: 2%;
  margin-left: 2%;
}

.characters {
  margin-left: 3%;
  color: #00afff;
}
</style>
